package com.one.shopping.ui.fragment;

import android.widget.Toast;

import com.one.shopping.R;
import com.one.shopping.adapter.CommonAdapter;
import com.one.shopping.adapter.OrdersAdapter;
import com.one.shopping.api.OneApi;
import com.one.shopping.entity.OrdersModule;
import com.one.shopping.entity.Result;
import com.one.shopping.ui.baseFragment.BaseSwipeRefreshFragment;
import com.one.shopping.util.GsonUtils;

import java.util.List;

/**
 * @author 柯尊诚
 * @version 1.0
 * @date 创建时间：2016/1/9 18:36
 */
public class OrdersItemFragment extends BaseSwipeRefreshFragment<OrdersModule> {

    @Override
    public CommonAdapter<OrdersModule> getAdapter() {
        return new OrdersAdapter(getActivity(), R.layout.list_item_orders);
    }

    @Override
    public List<OrdersModule> getDatas(byte[] responeString) {
        Result result = GsonUtils.fromJson(new String(responeString), Result.class);
        List<OrdersModule> orderses = GsonUtils.json2List(result.getData(), OrdersModule.class);

        return orderses;
    }

    @Override
    public void requestData() {
        OneApi.queryOrders(mHandler);
    }

    @Override
    public void onItemClick(int position, OrdersModule ordersModule) {
        Toast.makeText(getActivity(), ordersModule.getId(), Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onItemLongClick(int position, OrdersModule data) {

    }
}
